package club.terroir.server;
// club.terroir.server.ServletProducteur
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import club.terroir.server.folder.Folder_SSFactory;

public class ServletProducteur extends HttpServlet {

	private static final String ACTION_montrer_ajouter_client_formulaire ="montrer_ajouter_client_formulaire";
	private static final String ACTION_ajouter_client ="ajouter_client";
	private static final String ACTION_logout="logout";
	
	private static final long serialVersionUID = 1L;
	private String defaultLandingPage="/Club_terroir.jsp";


	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action =""+ request.getParameter("action");
		
		String target =defaultLandingPage;
		if (action.equals(ACTION_ajouter_client)){
			target ="/producteur/page_liste_clients.jsp";
		}else if (action.equals(ACTION_montrer_ajouter_client_formulaire)){
			target ="/producteur/page_ajouter_client.jsp";
		}else if (action.equals(ACTION_logout)){
			request.getSession().setAttribute("user", null);
			target ="/login.jsp"; 
		}else if (action.equals("testPersistsFolder")){
			String comment = Folder_SSFactory.getInstance().testInsertFolder();
			request.setAttribute("comment", comment);
			target ="/indexDebug.jsp"; 
		}else if (action.equals("testPersistsFolderList")){
			String comment = Folder_SSFactory.getInstance().testInsertFolderList();
			request.setAttribute("comment", comment);
			target ="/indexDebug.jsp"; 
		}
		
		RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(target);
		dispatcher.forward(request, response);
	}

	
}
